<extend name="Public/base" />
<block name="main">
    <section class="content-wrap">
        <div class="container">
            <div class="row">
                <main class="col-lg-10 col-lg-push-1 main-content">
                    <article class="post">
                        <div class="post-head">
                            <h1 class="post-title">{$Article['a_title']}</h1>
                            <div class="post-meta">
                                <time class="post-date" title="{$Article['create_time']}">
                                    <i class="fa fa-clock-o"></i>
                                    {$Article.create_time|date="Y-m-d H:i",###}
                                </time>
                            </div>
                        </div>
                        <div class="post-content">
                            {$Article['a_remark']}
                            <p>{$Article['a_content']}</p>
                        </div>
                        <footer class="post-footer clearfix">
                            <!--评论-->
                            <h4 class="bg-main text-white padding">评论区</h4>
                            <div class="dynamic-box">
                                <div class="comment-body">

                                    <volist name="comment" id="vo">
                                        <div class="media">
                                        <div class="media-left">
                                            <a href="#">
                                                <img class="media-object" width="60" height="60" src="__ROOT__{$vo.picture}" alt="...">
                                            </a>
                                        </div>
                                        <div class="media-body">
                                            <a class="reply-btn pull-right" data-toggle="review" data-id="{$vo.id}" data-username="{$vo.username}" href="javascript:;" reply="">回复<i></i></a>
                                            <h4 class="media-heading">{$vo.username}</h4>
                                            <p>{$vo.comment}</p>

                                            <volist name="vo.child" id="v">
                                                    <div class="media-left">
                                                        <a href="#">
                                                            <img class="media-object" width="60" height="60" src="__ROOT__{$v.picture}" alt="...">
                                                        </a>
                                                    </div>
                                                    <div class="media-body">
                                                        <a class="reply-btn pull-right" data-toggle="review" data-id="{$v.id}" data-username="{$v.username}" href="javascript:;" reply="">回复<i></i></a>
                                                        <h4 class="media-heading">{$v.username}</h4>
                                                        <p>{$v.comment}</p>

                                                        <volist name="v.child" id="v3">
                                                                <div class="media-left">
                                                                    <a href="#">
                                                                        <img class="media-object" width="60" height="60" src="__ROOT__{$v3.picture}" alt="...">
                                                                    </a>
                                                                </div>
                                                                <div class="media-body">
                                                                    <a class="reply-btn pull-right" data-toggle="review" data-id="{$v3.id}" data-username="{$v3.username}" href="javascript:;" reply="">回复<i></i></a>
                                                                    <h4 class="media-heading">{$vo.username}</h4>
                                                                    <p>{$vo.comment}</p>
                                                                </div>
                                                        </volist>
                                                    </div>
                                            </volist>
                                        </div>
                                        </div>
                                    </volist>

                                </div>
                                <div class="comment" style="margin-top: 10px;">
                                    <form class="clearfix comment-form" action="{:U('Article/comment')}" method="post">
                                        <input type="hidden" name="cid" value="{$Article.a_id}">
                                        <input type="hidden" name="uid" value="{$Think.session.uid}" />
                                        <input type="hidden" name="review_id" value="0">
                                        <div class="form-group">
                                            <textarea class="form-control" rows="4" placeholder="写下你的评论" name="content"></textarea>
                                        </div>
                                        <div class="clearfix">
                                            <a href="javascript:;" data-toggle="face"><i class="iconfont icon-biaoqing"></i></a>
                                            <button type="submit" class="btn btn-default" data-loading-text="请稍后...">回复</button>
                                            <a class="margin-left" data-toggle="close" href="javascript:;">取消</a>
                                        </div>
                                    </form>
                                </div>
                            </div>

                            <!--评论结束-->

                        </footer>
                    </article>
                    <div class="prev-next-wrap clearfix">
                        <div class="a-up pull-left">
                            <p>上一篇：
                                <if condition="$down['a_id'] eq 0">
                                    <a title='没有了'>&nbsp;没有了</a>
                                    <else />
                                    <a title='{$down.a_title}' href="{:U('Article/index',array('a_id'=>$down['a_id']))}">{$down.a_title}</a>
                                </if>
                            </p>
                        </div>
                        <div class="a-down pull-right">
                            <p>下一篇：
                                <if condition="$up['a_id'] eq 0">
                                    <a title='没有了'>&nbsp;没有了</a>
                                    <else />
                                    <a title='{$up.a_title}' href="{:U('Article/index',array('a_id'=>$up['a_id']))}">{$up.a_title}</a>
                                </if>
                            </p>
                        </div>
                    </div>
                </main>
            </div>
        </div>
    </section>
    <script type="text/javascript">
        $(function() {
            //插入回复表单
            $(".dynamic-box").on('click', '[data-toggle="review"]', function(event) {
                var $form = $(".dynamic-box").find('.comment-form');
                var $textarea = $form.find("[name='content']");
                $form.appendTo($(this).next().next());

                $form.find(':hidden[name=review_id]').val($(this).data('id'));
                //对回复回复的处理
                if ($(this).data('username')!=='') {
                    $textarea.val('回复 @' + $(this).data('username') + ' : ');
                } else {
                    $textarea.val('');
                }
                moveEnd($textarea.get(0));
                event.stopPropagation();
            });

            //点击评论框以外的地方，重置评论表单
            /*$(document).click(function() {
             // alert(1111111111);
             var $form = $(".dynamic-box").find('.comment-form');
             if ($form.length > 0) {
             if ($form.find(':hidden[name=review_id]').val() !== '0') {
             $form.parents(".dynamic-box").find(".comment-form").before($form);
             $form.find(':hidden[name=review_id]').val(0);
             $form.find('textarea').val('');
             }
             }
             });*/
            //关闭
            $(".dynamic-box").on('click', "[data-toggle='close']", function(event) {
                var $form = $(".dynamic-box").find('.comment-form');
                if ($form.length > 0) {
                    if ($form.find(':hidden[name=review_id]').val() !== '0') {
                        $form.parents(".dynamic-box").find(".comment-form").before($form);
                        $form.find(':hidden[name=review_id]').val(0);
                        $form.find('textarea').val('');
                    }
                }
                $(this).parents('.comment-form').remove();
                $form.appendTo($('.comment'));
                event.stopPropagation();
            });

            $(".dynamic-box").on('click', 'textarea', function(event) {
                event.stopPropagation();
            });

        });
    </script>
</block>


